package com.dkd.manage.controller;

import com.dkd.common.core.domain.R;
import com.dkd.manage.pojo.dto.VmTypeQueryListDto;
import com.dkd.manage.pojo.entity.VmType;
import com.dkd.manage.result.PageResult;
import com.dkd.manage.service.VmTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "设备类型管理相关接口")
@RequestMapping("/manage/vmType")
public class VmTypeController {

    @Autowired
    private VmTypeService vmTypeService;

    @ApiOperation("分页查询设备类型列表")
    @PreAuthorize("@ss.hasPermi('manage:vmType:list')")
    @GetMapping("/list")
    public R<PageResult<VmType>> list(VmTypeQueryListDto vmTypeQueryListDto) {
        log.info("分页查询设备类型列表：{}", vmTypeQueryListDto);
        PageResult<VmType> result = vmTypeService.list(vmTypeQueryListDto);
        return R.ok(result);
    }

    @ApiOperation("新增设备类型")
    @PreAuthorize("@ss.hasPermi('manage:vmType:add')")
    @PostMapping
    public R<Integer> add(@RequestBody VmType vmType) {
        log.info("新增设备类型：{}", vmType);
        Integer rows = vmTypeService.add(vmType);
        return R.ok(rows);
    }

    @ApiOperation("根据id查询设备类型")
    @PreAuthorize("@ss.hasPermi('manage:vmType:query')")
    @GetMapping("/{id}")
    public R<VmType> getVmTypeById(@PathVariable Long id) {
        log.info("根据id查询设备类型：{}", id);
        VmType vmType = vmTypeService.getVmTypeById(id);
        return R.ok(vmType);
    }

    @ApiOperation("修改设备类型")
    @PreAuthorize("@ss.hasPermi('manage:vmType:edit')")
    @PutMapping
    public R<Integer> edit(@RequestBody VmType vmType) {
        log.info("修改设备类型：{}", vmType);
        Integer rows = vmTypeService.edit(vmType);
        return R.ok(rows);
    }

    @ApiOperation("根据id删除设备类型")
    @PreAuthorize("@ss.hasPermi('manage:vmType:remove')")
    @DeleteMapping("/{ids}")
    public R<Integer> deleteVmTypeById(@PathVariable Long[] ids) {
        log.info("根据id删除设备类型：{}", ids);
        Integer rows = vmTypeService.deleteVmTypeById(ids);
        return R.ok(rows);
    }

}
